<!doctype html>
<html lang="en">
<head>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f0f4f8;
            font-family: 'Arial', sans-serif;
            color: #2c3e50;
        }
        .container {
            max-width: 700px;
            margin-top: 60px;
            padding: 30px;
            background-color: #fff;
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h2 {
            color: #2980b9;
            text-align: center;
            margin-bottom: 30px;
        }
        .form-control:focus {
            border-color: #2980b9;
            box-shadow: 0 0 0 0.2rem rgba(41, 128, 185, 0.5);
        }
        .btn-primary {
            background-color: #2980b9;
            border-color: #2980b9;
            padding: 10px 25px;
            font-size: 1rem;
            transition: all 0.3s ease;
        }
        .btn-primary:hover {
            background-color: #2c3e50;
            border-color: #2c3e50;
        }
        .btn-secondary {
            background-color: #ecf0f1;
            border-color: #bdc3c7;
            color: #2c3e50;
        }
        .btn-secondary:hover {
            background-color: #bdc3c7;
            border-color: #95a5a6;
        }
        .alert {
            border-radius: 10px;
        }
        .img-fluid {
            max-width: 200px;
            height: auto;
            border-radius: 8px;
        }
        .table th {
            vertical-align: middle;
            background-color: #ecf0f1;
            color: #2c3e50;
        }
        .table td {
            vertical-align: middle;
            padding: 15px;
        }
        .edit-mode {
            display: none;
        }
    </style>
    <title>Hockey Hero Management</title>
</head>
<body>
<div class="container">
    <?php if (isset($editMode)): ?>
        <h2>Edit Hockey Hero</h2>
        <form action="<?= base_url('hockey/update/' . esc($record['id'])) ?>" method="post" class="row g-3">
            <?= csrf_field() ?>

            <?php if (isset($errors)): ?>
                <div class="alert alert-danger alert-dismissible fade show col-12" role="alert">
                    <?php foreach ($errors as $error): ?>
                        <p><?= esc($error) ?></p>
                    <?php endforeach; ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            <?php endif; ?>

            <div class="col-md-12 mb-3">
                <label for="name" class="form-label">Name</label>
                <input type="text" class="form-control" id="name" name="name" value="<?= esc($record['name']) ?>">
            </div>

            <div class="col-md-12 mb-3">
                <label for="city" class="form-label">City</label>
                <input type="text" class="form-control" id="city" name="city" value="<?= esc($record['city']) ?>">
            </div>

            <div class="col-12 mb-3">
                <label for="powers" class="form-label">Powers</label>
                <textarea class="form-control" id="powers" name="powers"><?= esc($record['powers']) ?></textarea>
            </div>

            <div class="col-md-12 mb-3">
                <label for="weapon" class="form-label">Weapon</label>
                <input type="text" class="form-control" id="weapon" name="weapon" value="<?= esc($record['weapon']) ?>">
            </div>

            <div class="col-12 d-flex justify-content-between mt-4">
                <button type="submit" class="btn btn-primary">Update Hero</button>
                <a href="<?= base_url('hockey/showme/' . esc($record['id'])) ?>" class="btn btn-secondary">Cancel</a>
            </div>
        </form>
    <?php else: ?>
        <h2>Hockey Hero Details</h2>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Field</th>
                    <th>Value</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>ID</td>
                    <td><?= esc($record['id']) ?></td>
                </tr>
                <tr>
                    <td>Name</td>
                    <td><?= esc($record['name']) ?></td>
                </tr>
                <tr>
                    <td>City</td>
                    <td><?= esc($record['city']) ?></td>
                </tr>
                <tr>
                    <td>Powers</td>
                    <td><?= esc($record['powers']) ?></td>
                </tr>
                <tr>
                    <td>Weapon</td>
                    <td><?= esc($record['weapon']) ?></td>
                </tr>
                <tr>
                    <td>Image</td>
                    <td><img src="/image/<?= esc($record['image']) ?>" alt="<?= esc($record['name']) ?>" class="img-fluid"></td>
                </tr>
            </tbody>
        </table>
        <div class="d-flex justify-content-center mt-4">
            <a href="#" id="editButton" class="btn btn-warning px-5">Edit Hero</a>
        </div>
    <?php endif; ?>
</div>

<!-- 引入Bootstrap JS和依赖 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.getElementById('editButton').addEventListener('click', function(event) {
        event.preventDefault();
        // Redirect to edit mode with the current record ID
        window.location.href = '<?= base_url('hockey/edit/' . esc($record['id'])) ?>';
    });
</script>
</body>
</html>